package com.codoon.unova.view;

import com.codoon.unova.ui.HorizontalBaseActivity;
import com.codoon.unova.util.LogUtil;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;

@SuppressLint("NewApi")
public class MyLinearLayout extends LinearLayout {
	
	
	public enum Direction{
		LEFT,REIGHT,PREVIOUS
	}
	
	private LayoutTouchLintener lintener;

	public MyLinearLayout(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public MyLinearLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public MyLinearLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	
	public void setLayoutTouchLintener(LayoutTouchLintener lintener){
		this.lintener=lintener;
	}
	
	private float point_x;
	private float point_y;

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		super.onTouchEvent(event);
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:

			LogUtil.info(HorizontalBaseActivity.class, "--ACTION_DOWN--x=" + point_x + ",y=" + point_y);
			point_x = event.getX();
			point_y = event.getY();
			break;
		case MotionEvent.ACTION_UP:
			LogUtil.info(HorizontalBaseActivity.class, "--ACTION_DOWN--xd=" + (event.getX() - point_x) + "  ,yd="
					+ (event.getY() - point_y));
			if (event.getX() - point_x > 50) {
				lintener.changeView(Direction.LEFT);
			} else if (event.getX() - point_x < -50) {
				lintener.changeView(Direction.REIGHT);
			} else if (event.getY() - point_y < -50) {
				lintener.changeView(Direction.PREVIOUS);
			}
			break;

		default:
			break;
		}

		return true;
	}

	
	public interface LayoutTouchLintener{
		public void changeView(Direction status);
	}
}
